﻿using jstreeMVCWrapper.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace jstreeMVCWrapper.Controllers
{
	public class HomeController : Controller
	{
		public ActionResult Index()
		{
			TreeModel model = new TreeModel();
			model.TreeNodes = getTreeNodes();
			return View("Index", model);
		}

		private IEnumerable<Node> getTreeNodes()
		{
			List<Node> nodes = new List<Node>();
			nodes.Add(new Node()
			{
				NodeID = 1,
				NodeName = "Root1",
				NodeType = eNodeType.Folder,
				Childern = new List<Node>()
				{
					new Node(){NodeID=2, NodeName="Folder1", NodeType = eNodeType.Folder},
					new Node(){NodeID=3, NodeName="Folder2", NodeType = eNodeType.Folder},
					new Node(){
						NodeID=4, 
						NodeName="Folder3", 
						NodeType = eNodeType.Folder,
						Childern = new List<Node>()
						{
							new Node(){NodeID=5, NodeName="Folder3.1", NodeType = eNodeType.Folder},
							new Node(){NodeID=6, NodeName="Folder3.2", NodeType = eNodeType.Folder},
							new Node(){
								NodeID=7, 
								NodeName="Folder3.3", 
								NodeType = eNodeType.Folder,
								Childern =  new List<Node>()
								{
									new Node(){NodeID=20, NodeName="File 1", NodeType = eNodeType.File},
									new Node(){NodeID=21, NodeName="File 2", NodeType = eNodeType.File},
								},
							},
						},
					},
					new Node(){NodeID=22, NodeName="File 3", NodeType = eNodeType.File},
					new Node(){NodeID=23, NodeName="File 4", NodeType = eNodeType.File},
				},
			});

			nodes.Add(new Node()
			{
				NodeID = 8,
				NodeName = "Root1",
				NodeType = eNodeType.Folder,
				Childern = new List<Node>()
				{
					new Node(){NodeID=9, NodeName="Folder1", NodeType = eNodeType.Folder},
					new Node(){NodeID=10, NodeName="Folder2", NodeType = eNodeType.Folder},
					new Node(){NodeID=11, NodeName="Folder3", NodeType = eNodeType.Folder},
				},
			});
			return nodes;
		}

	}
}

